package com.java1412.controller;

import com.java1412.dao.UsersMapper;
import com.java1412.entity.Users;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author java1412
 * @create 2021-05-20 11:33
 */
@RestController
@RequestMapping("/user")
public class UserController {
    @Autowired
    private UsersMapper usersMapper;

    @GetMapping("/{id}")
    public Users findUserById(@PathVariable("id") Integer id) {
        return usersMapper.findUserById(id);
    }

    @PostMapping("")
    public String addUser(@RequestBody Users users) {
        usersMapper.insertUsers(users);
        return "success";
    }

    @PostMapping("/update")
    public String updateUser(@RequestBody Users users) {
        usersMapper.updateUser(users);
        return "success";
    }

    @DeleteMapping("/{id}")
    public String delUserById(@PathVariable("id") Integer id) {
        usersMapper.deleteById(id);
        return "success";
    }
}
